<div class="admin blog">
  <div class="section header dark-50">
    <h2 class="light"><%= @blog_edit_entry ? "Edit" : "Add" %> Blog Entry</h2>
  </div>
  
  <div class="entry">
    <% form_remote_tag(
        :url => { 
          :action     => "blog_submit" },
        :complete => 
          "Submit.genericAfterSubmit",
        :before => "Submit.genericSubmit();"
        ) do %>
        
      <%= hidden_field_tag "id", @blog_edit_entry ? @blog_edit_entry.id : 0 %>
        
      <div class="top">
        <%= text_field_tag(
              "title", 
              @blog_edit_entry ? @blog_edit_entry.title : nil, 
              :id => nil,
              :class => "default blog_title",
              :autocomplete => "off") %>
      </div>
      <div class="main">
        <div>
          <%= text_area_tag(
                "body", 
                @blog_edit_entry ? @blog_edit_entry.body : nil, 
                :id => "blog_body",
                :class => "default blog_body") %>
        </div><br/>

        <div>
          <b>Add Attachments: </b> 
          <%= link_to_function("Song", "Admin.addSong()") %>
          <%= link_to_function("Photos", "Admin.selectAttachmentType('photos')") %>
          <%= link_to_function("Goals", "Admin.selectAttachmentType('goals')") %>
          <br/><br/>
          
          <div id="attachable_container">
            <% if @blog_edit_entry %>
              <% @blog_edit_entry.attachments.each do |attachment| %>
                <select class="default" name="attachments[]">
                  <option class="default" value=""> - </option>
                  <option class="default" selected="selected" value="<%= "#{attachment.attachable.class.to_s},#{attachment.attachable.id}" %>">
                    <%= h attachment.attachable.name %>
                  </option>
                </select>
              <% end %>
            <% end %>
          </div>
        </div>
      </div>
      <div class="bottom">
        <div class="submit">
          <%= submit_tag "Submit", :class => "default submit" %>  
        </div>
        <div class="tags">
          <%= text_field_tag(
                "tags", 
                @blog_edit_entry ? (@blog_edit_entry.tags.collect{ |tag| tag.name } * ' ') : nil, 
                :id => nil,
                :class => "default blog_tags",
                :autocomplete => "off") %>
        </div>
        <br class="clear"/>
      </div>
      
    <% end %>
  </div>
  <br/>
  
  <div class="section header dark-50">
    <h2 class="light">Recent Blog Entries</h2>
  </div>
  <div class="section body dark-25">
    <% @blog_entries.each do |blog_entry| %> 
      <%= link_to( h(blog_entry.title), admin_blog_edit_url(:id => blog_entry.id) ) %> - <%= blog_entry.created_at.to_s(:long) %>
      <br/>
    <% end %>
  </div>
</div>